package org.shana.shortlink.core.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.shana.shortlink.core.common.convention.result.Result;
import org.shana.shortlink.core.common.convention.result.Results;
import org.shana.shortlink.core.dto.req.*;
import org.shana.shortlink.core.dto.resp.ShortLinkPageRespDTO;
import org.shana.shortlink.core.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 回收站管理控制层
 */
@RestController
@RequestMapping("/api/v1/short-link/recycle-bin")
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;

    /**
     * 保存回收站
     */
    @PostMapping("/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        recycleBinService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 分页查询回收站短链接
     */
    @GetMapping("page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
        List<String> gidList = requestParam.getGidList();
//        if(gidList==null|| gidList.isEmpty()){
//            if (gidList != null) {
//                gidList.add("89");
//            }
//        }
        return Results.success(recycleBinService.pageShortLink(requestParam));
    }


    /**
     * 恢复短链接
     */
    @PostMapping("/recover")
    public Result<Void> recoverRecycleBin(@RequestBody RecycleBinRecoverReqDTO requestParam) {
        recycleBinService.recoverRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 移除短链接
     */
    @PostMapping("/remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveReqDTO requestParam) {
        recycleBinService.removeRecycleBin(requestParam);
        return Results.success();
    }

}
